local ex__wansha = fk.CreateSkill {

  name = "joyex__wansha",

  tags = { Skill.Compulsory, },

}



ex__wansha:addEffect(fk.EventPhaseStart, {
  name = "joyex__wansha",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(ex__wansha.name) and player.phase == Player.Play
  end,
  on_cost = function (self, event, target, player, data)
    local tars = {}
    for _, p in ipairs(player.room.alive_players) do
      if p.hp > 1 then
        table.insertIfNeed(tars,p.id)
      end
    end
    if #tars > 0 then
      local tar = player.room:askForChoosePlayers(player,tars,1,1,"完杀：你可令一名体力值大于1的角色失去1点体力，然后此阶段结束时其回复1点体力")
      if #tar > 0 then
        event:setCostData(self, tar[1])
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local p = player.room:getPlayerById(event:getCostData(self))
    player.room:setPlayerMark(p,"@@joyex__wansha-phase",1)
    player.room:loseHp(p,1,ex__wansha.name)
  end,
})
ex__wansha:addEffect(fk.EventPhaseEnd, {
  refresh_events = {fk.EventPhaseEnd},
  can_refresh = function(self, event, target, player, data)
    return  player:getMark("@@joyex__wansha-phase") > 0 and player:isWounded()
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:recover({
      who = player,
      num = 1,
      skillName = ex__wansha.name
    })
  end,
})

ex__wansha:addEffect("prohibit", {
  name = "#joyex__wansha_prohibit",
  frequency = Skill.Compulsory,
  prohibit_use = function(self, player, card)
    return card and card.name == "peach" and table.find(Fk:currentRoom().alive_players, function (p)
      return p.phase ~= Player.NotActive and p ~= player and p:hasSkill(ex__wansha)
    end)
  end,
})

return ex__wansha